from flask import Flask,request
import os
import config
app = Flask(__name__)

@app.route('/')
def index():
    return '<div style="text-align:center;margin-top:10%;"><h3>WebHook is running by uwsgi<h3></div>'

@app.route('/hook',methods=['POST'])
def hook():
    if request.method == 'POST':
        name = request.args.get('name')
        data = request.get_json()
        if data['password'] == config.commandPassWord:
            #print("Received webhook data:", config.commandPassWord)
            if name in config.commandList :
                command = config.commandList[name]
                status = os.system(command)
                if status == 0 :
                    return "<p>执行命令：</p>"+command
                else:
                    return "<p>执行命令失败：</p>"+status
            else:
                return "<p>参数有问题！</p>"
        else:
            return "<p>密码错误！</p>"
    # else:
    #     abort(404)
    #     return None

if __name__ =='__main__':
    app.run(host='0.0.0.0',port=config.port)
